package xu.jiang.report.dto;

import lombok.Data;
import org.apache.poi.ss.util.CellRangeAddress;

@Data
public class RectangleArea {
    private int firstRow = 0;
    private int lastRow = 0;
    private int firstCol = 0;
    private int lastCol = 0;

    public RectangleArea(){

    }

    public RectangleArea(int firstRow, int lastRow, int firstCol, int lastCol) {
        this.firstRow = firstRow;
        this.lastRow = lastRow;
        this.firstCol = firstCol;
        this.lastCol = lastCol;
    }

    /**
     * 水平移动的列数
     * @param offCols
     * @return
     */
    public RectangleArea moveByHorizontal(int offCols){
        this.firstRow += offCols;
        this.lastRow += offCols;
        return this;
    }

    /**
     * 宽度
     * @return
     */
    public int getWidth(){
        return this.lastCol-this.firstCol;
    }
    /**
     * 高度
     * @return
     */
    public int getHeight(){
        return this.lastRow-this.firstRow;
    }
    /**
     * 垂直移动的列数
     * @param offRows
     * @return
     */
    public RectangleArea moveByVertical(int offRows){
        this.firstCol += offRows;
        this.lastCol += offRows;
        return this;
    }

    /**
     * 是否与 target 是相同的区域
     * 相同定义：宽、高 都相同即为相同
     * @param target
     * @return
     */
    public boolean isTheSameAs(RectangleArea target){
        if(target==null){
            return false;
        }

        if(target.getWidth()==this.getWidth()&&target.getHeight()==this.getHeight()){
            return true;
        }
        return false;
    }

    /**
     * 是否包含合并单元格
     * @param mergeCell
     * @return
     */
    public boolean isInclusiveOf(CellRangeAddress mergeCell){

        if(mergeCell==null){
            return false;
        }
        if(     this.getFirstRow()<=mergeCell.getFirstRow()
                && mergeCell.getLastRow()<=this.getLastRow()

                && this.getFirstCol()<=mergeCell.getFirstColumn()
                && mergeCell.getLastColumn()<=this.getLastCol()
        ){
            return true;
        }
        return false;
    }
}
